class ParamsTypeError(Exception):
    def __init__(self, n):
        self.num = n


def fibw(n):  # 写出从第0项到第n项的Fibonacci系列
    a, b, i = 0, 1, 0
    while i <= n-1:
        print(a, end=' ')
        a, b, i = b, a+b, i+1
    # 输出一个空行，便于显示，没有在main里使用换行符
    print()


def fibf(n):
    a, b = 0, 1
    for s in range(1, n+1):
        print(a, end=' ')
        a, b = b, a+b


if __name__ == '__main__':
    try:
        num = input("输入需要几项（正整数）：")
        if not num.isdigit():
            raise ParamsTypeError(num)
        num = int(num)
        if num <= 0:
            print("请输入一个正整数！")
    except ParamsTypeError as p:
        print("ParamsTypeError:请输入正整数！你输入的是：", p.num)
    else:
        print("while循环：")
        fibw(int(num))
        print("for循环：")
        fibf(int(num))
